//
//  AppDelegate.swift
//  Seed
//
//  Created by Samuel on 2017/6/5.
//  Copyright © 2017年 RedSoft. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    
    //todo:更换为seed的 友盟 和 微信 appkey
    private let umAppkey = "5937a93099f0c7518b00182d"
    
    private var isLogin:Bool = false{
        didSet{
            if isLogin {
                window?.rootViewController = YMTabBarController()
            }else{
                window?.rootViewController = UIStoryboard.initialViewController("Login")
            }
        }
    }
    
    func setLoginStatus(_ status:Bool ) {
        UserDefaults.standard.set(status, forKey: isUserLogin)
        UserDefaults.standard.synchronize()
        isLogin = status
    }
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.makeKeyAndVisible()
        
        isLogin = UserDefaults.standard.bool(forKey: isUserLogin)
        configUMeng()
        
        return true
    }
    

    func configUMeng(){
        UMSocialManager.default().openLog(true)
        UMSocialManager.default().umSocialAppkey = umAppkey
        UMSocialManager.default().removePlatformProvider(with: .wechatFavorite)
        UMSocialManager.default().setPlaform(.wechatSession, appKey: "wxa0a88b45cd9659c4", appSecret: "b3926716fba8236df9263222a260b417", redirectURL: "www.google.com")
    }
    
    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
        let result = UMSocialManager.default().handleOpen(url, options: options)
        return result
    }
    
    func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
        let result = UMSocialManager.default().handleOpen(url)
        return result
    }
    
}

